package com.miss.spjyx.widget

import android.content.Context
import android.support.v7.app.AlertDialog
import android.view.Gravity
import android.widget.LinearLayout
import android.widget.ProgressBar

/**
 *  进度条
 *
 * @author wl
 * @since 2019/08/31 18:18
 */
object ProgressDialog {
    var dialog: AlertDialog? = null

    fun show(ctx: Context) {
        try {
            if (dialog == null) {
                val linearLayout = LinearLayout(ctx)
                linearLayout.gravity = Gravity.CENTER
                linearLayout.setPadding(0, 40, 0, 40)
                val progressBar = ProgressBar(ctx)
                progressBar.isIndeterminate = true
                linearLayout.addView(progressBar)
                dialog = AlertDialog.Builder(ctx)
                    .setCancelable(false)
                    .setView(linearLayout)
                    .create()
            }
            dialog?.show()
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    fun dismiss() {
        if (dialog?.isShowing == true) {
            dialog?.dismiss()
        }
    }
}